/*****************************************************************************/
/* CS 230 Final Project                                                      */
/* simulation.cpp			                                                 */
/* Entry point for running command line version of the program               */
/*                			                                                 */
/* Created by Even Cheng and Shu-Chi Hsu                                     */
/* Copyright 2011 GNU GPL v3                                                 */
/*****************************************************************************/

#include "stdafx.h"
#include <iostream>
#include <fstream>
#include <time.h>
#include "graph.h"
#include <Windows.h>
#include "events.h"

using namespace std;



void main()
{
	int nodes_number = MAX_NODE_NUMBER;
	int number = 0;
	int con = 1;
	int clock = 0;
	int flag;
	int node = 0;

	graph sim;
	
	cout << "start reading map... ";
	sim.Readmap();
	cout << "finished reading" << endl;
	sim.humancontact();
	events queue;
	queue.sort();


	for(clock=0;clock<=MAX_RUNNING_TIME;clock++)
	{
		if(node > MAX_NODE_NUMBER)	continue;

		while(queue.head!= NULL && clock >= queue.head->clock)
		{
			flag = queue.simulate(&sim, clock, &node);

			if(flag == 1 || flag == 0)
			{
				sim.nodes[node].on = flag;
			}

			
		}

		Sleep(500);
	}
	cout << endl << "Within the time frame of " << MAX_RUNNING_TIME << " ticks, there are " << queue.nodesReceivedMessage << " nodes received message" << endl;
	cout << endl << "All schedules have been executed and finished." << endl;
	system("pause");
}

